﻿using System;
using System.Drawing;

namespace LevelEditor.Document
{
    [Serializable]
    public enum TileType
    {
        None,
        Passable = None,
        Impassable,
        Wall = Impassable//,
        //PixelCollision,
        //Slope = PixelCollision
        //Door,
        //Portal
    }

    [Serializable]
    public class Tile
    {

        #region Properties

        ///// <summary>
        ///// Where in tile grid this tile is placed
        ///// </summary>
        //public Point Position { get; set; }

        /// <summary>
        /// Index of tile set to use
        /// </summary>
        public int TileSetIndex { get; set; }
        
        /// <summary>
        /// Index of tile from the tile set to use
        /// </summary>
        public int TileIndex { get; set; }

        /// <summary>
        /// Is this tile an obstacle for the player via the x-axis?
        /// </summary>
        public bool ObstacleX { get; set; }

        /// <summary>
        /// Is this tile an obstacle for the player via the y-axis?
        /// </summary>
        public bool ObstacleY { get; set; }

        /// <summary>
        /// Left floor position of tile for slopes
        /// </summary>
        public int LeftFloor { get; set; }

        /// <summary>
        /// Right floor position of tile for slopes
        /// </summary>
        public int RightFloor { get; set; }

        public TileType Type { get; set; }

        ///// <summary>
        ///// Level file/name that this tile connects to.
        ///// Only matters if type is Door or Portal.
        ///// </summary>
        //public string ConnectsTo { get; set; }

        #endregion

        #region Constructors

        public Tile()
        {
            TileSetIndex = -1;
        }

        public Tile(Tile copy)
        {
            TileSetIndex = copy.TileSetIndex;
            TileIndex = copy.TileIndex;
            ObstacleX = copy.ObstacleX;
            ObstacleY = copy.ObstacleY;
            LeftFloor = copy.LeftFloor;
            RightFloor = copy.RightFloor;
            //ConnectsTo = copy.ConnectsTo;
        }

        #endregion

        #region Equal checks

        public bool NormalEquals(Tile otherTile)
        {
            return TileIndex == otherTile.TileIndex && TileSetIndex == otherTile.TileSetIndex;
        }

        public bool WallEquals(Tile otherTile)
        {
            return Type == otherTile.Type;
        }

        #endregion

        //#region Equals, == != operators, hash code

        //public override bool Equals(object obj)
        //{
        //    if(obj == null)
        //        return false;
        //    Tile t = (obj as Tile);
        //    if((object)t == null)
        //        return false;
        //    return TileSetIndex == t.TileSetIndex && TileIndex == t.TileIndex && Type == t.Type;
        //}

        //public bool Equals(Tile t)
        //{
        //    if ((object)t == null)
        //        return false;
        //    return TileSetIndex == t.TileSetIndex && TileIndex == t.TileIndex && Type == t.Type;
        //}

        //public static bool operator ==(Tile a, Tile b)
        //{
        //    if (ReferenceEquals(a, b))
        //        return true;
        //    if ((object)a == null || (object)b == null)
        //        return false;
        //    return a.TileSetIndex == b.TileSetIndex && a.TileIndex == b.TileIndex && a.Type == b.Type;
        //}

        //public static bool operator !=(Tile a, Tile b)
        //{
        //    return !(a == b);
        //}

        //public override int GetHashCode()
        //{
        //    return base.GetHashCode();
        //}

        //#endregion

    }
}
